<template>
  <div class="app-container">
    <!-- <a-title @clickPreview="preview" /> -->
    <a-title />
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="140px"
    >
      <el-form-item label="流程类型" prop="sheetCode">
        <el-select
          v-model="queryParams.sheetCode"
          placeholder="请选择流程类型"
          clearable
          filterable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in workflowTypes"
            :key="item.url"
            :label="item.workflowName"
            :value="item.url"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目代码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入项目代码"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目负责人" prop="projectLeader">
        <el-input
          v-model="queryParams.projectLeader"
          placeholder="请输入项目负责人"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务名称" prop="businessName">
        <el-input
          v-model="queryParams.businessName"
          placeholder="请输入业务名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报告号/招标号" prop="reportNo">
        <el-input
          v-model="queryParams.reportNo"
          placeholder="请输入报告号/招标号"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务类别" prop="businessTypeId">
         <el-cascader
          v-model="queryParams.businessTypeId"
          :options="categoryOptions"
          :show-all-levels="false"
          :props="{ value: 'id', emitPath: false }"
          filterable
          clearable
          style="width: 240px"
          placeholder="请选择业务类别"
        />
      </el-form-item>
      <el-form-item label="发起人" prop="origin">
        <el-input
          v-model="queryParams.origin"
          placeholder="请输入发起人"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发起时间">
        <el-date-picker
          v-model="queryParams.workflowStartTime"
          type="daterange"
          range-separator="-"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 240px"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="完成时间">
        <el-date-picker
          v-model="queryParams.workflowEndTime"
          type="daterange"
          range-separator="-"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 240px"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="驳回内容" prop="rejectContent">
        <el-input
          v-model="queryParams.rejectContent"
          placeholder="请输入驳回内容"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驳回时间" prop="rejectTime">
        <el-date-picker
          v-model="queryParams.rejectTime"
          type="daterange"
          range-separator="-"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 240px"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="驳回节点" prop="rejectNode">
        <el-input
          v-model="queryParams.rejectNode"
          placeholder="请输入驳回节点"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleSycn"
          >同步</el-button
        >
        <!--v-hasPermi="['system:no:export']"-->
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出</el-button
        >
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="opinionList"
      @sort-change="tableSortChange"
      :default-sort="{ prop: 'rejectTime', order: 'descending' }"
    >
      <el-table-column
        label="流程类型"
        align="center"
        prop="workflowName"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="项目名称"
        align="center"
        prop="projectName"
        width="200"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="项目代码"
        align="center"
        prop="code"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="项目负责人"
        align="center"
        prop="projectLeader"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="业务名称"
        align="center"
        prop="businessName"
        width="200"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="报告号/招标号"
        align="center"
        prop="reportNo"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="业务类别"
        align="center"
        prop="businessTypeName"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="发起人"
        align="center"
        prop="origin"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="发起时间"
        align="center"
        prop="originTime"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="完成时间"
        align="center"
        prop="endTime"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="驳回人"
        align="center"
        prop="rejectUser"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="驳回内容"
        align="center"
        prop="rejectContent"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="驳回时间"
        align="center"
        prop="rejectTime"
        width="180"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rejectTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="驳回节点"
        align="center"
        prop="rejectNode"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listOpinion, exportOpinion } from "@/api/system/opinion";
import { syncRejectList } from "@/api/rejectComment/rejectComment";
import { treeselect } from "@/api/system/business_category";
import { workflowTypelist } from "@/api/system/workflowConfig";
import aTitle from "@/components/Title";
export default {
  name: "Opinion",
  components: { aTitle },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 流程驳回意见表格数据
      opinionList: [],
      categoryOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        instanceName: undefined,
        sheetCode: undefined,
        rejectUser: undefined,
        rejectContent: undefined,
        rejectTime: undefined,
        instanceId: undefined,
        rejectNode: undefined,
        projectName: undefined,
        code: undefined,
        projectLeader: undefined,
        businessName: undefined,
        reportNo: undefined,
        businessTypeName: undefined,
        origin: undefined,
        workflowStartTime: undefined,
        workflowEndTime: undefined,
        businessTypeId:undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      workflowTypes: [],
    };
  },
  created() {
    this.getListWorkflowConfig();
    treeselect().then((res) => {
      if (res.code === 200) {
        this.categoryOptions = res.data;
      }
    });
    this.getList();
  },
  methods: {
    getListWorkflowConfig() {
      workflowTypelist().then((res) => {
        this.workflowTypes = res.data;
      });
    },
    handleSycn() {
      var $this = this;
      syncRejectList().then((res) => {
        if (res.code === 200 && res.data >= 0) {
          $this.msgSuccess("同步成功");
          $this.getList();
        }
      });
    },
    /** 查询流程驳回意见列表 */
    getList() {
      this.loading = true;
      var reqParams = {
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        sheetCode: this.queryParams.sheetCode,
        rejectUser: this.queryParams.rejectUser,
        rejectContent: this.queryParams.rejectContent,
        rejectNode: this.queryParams.rejectNode,
        projectName: this.queryParams.projectName,
        order: this.queryParams.order,
        businessTypeId: this.queryParams.businessTypeId,
        code: this.queryParams.code,
        reportNo: this.queryParams.reportNo,
        projectLeader:this.queryParams.projectLeader,
        businessName:this.queryParams.businessName,
        origin:this.queryParams.origin
      };

      if (this.queryParams.workflowStartTime) {
        reqParams.originTimeStart = this.queryParams.workflowStartTime[0];
        reqParams.originTimeEnd = this.queryParams.workflowStartTime[1];
      }
      if (this.queryParams.workflowEndTime) {
        reqParams.endTimeStart = this.queryParams.workflowEndTime[0];
        reqParams.endTimeEnd = this.queryParams.workflowEndTime[1];
      }

      if (this.queryParams.rejectTime) {
        reqParams.rejectTimeStart = this.queryParams.rejectTime[0];
        reqParams.rejectTimeEnd = this.queryParams.rejectTime[1];
      }

      listOpinion(reqParams).then((response) => {
        this.opinionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      //this.resetForm("queryForm");
      this.queryParams={
        pageNum: 1,
        pageSize: 10,
        instanceName: undefined,
        sheetCode: undefined,
        rejectUser: undefined,
        rejectContent: undefined,
        rejectTime: undefined,
        instanceId: undefined,
        rejectNode: undefined,
        projectName: undefined,
        code: undefined,
        projectLeader: undefined,
        businessName: undefined,
        reportNo: undefined,
        businessTypeName: undefined,
        origin: undefined,
        workflowStartTime: undefined,
        workflowEndTime: undefined,
        businessTypeId:undefined
      };
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有流程驳回意见数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportOpinion(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        })
        .catch(function () {});
    },
    tableSortChange(column) {
      this.queryParams.pageNum = 1;

      if (column.order === "descending") {
        this.queryParams.sortBy = column.prop;
        this.queryParams.order = "desc";
      } else {
        this.queryParams.sortBy = column.prop;
        this.queryParams.order = "asc";
      }
      this.getList();
    },
  },
};
</script>